﻿using A.M.ETO;
using A.M.Storage.Application;
using A.M.Storage.I_Infrastruecure;
using L.M.System.Application.IServices;
using L.M.System.Domain.Entity;
using L.M.System.Infrastruecure.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace L.M.System.Application.Services
{
    public class Authority_listServices : BaseServices<authority_list, string>, IAuthority_listServices
    {
        private readonly IAuthority_listRepository authority_ListRepository;
        /// <summary>
        ///   员工角色
        /// </summary>
        private readonly IEmployee_role_tableServices employee_role_tableServices;
        /// <summary>
        /// 角色主权限
        /// </summary>
        private readonly IRole_permission_tableRepository role_Permission_TableRepository;

        public Authority_listServices(IAuthority_listRepository authority_ListRepository, IEmployee_role_tableServices employee_role_tableServices, IRole_permission_tableRepository role_Permission_TableRepository) : base(authority_ListRepository)
        {
            this.authority_ListRepository = authority_ListRepository;
            this.employee_role_tableServices = employee_role_tableServices;
            this.role_Permission_TableRepository = role_Permission_TableRepository;
        }


        /// <summary>
        /// 通过用户返回顶部导航
        /// </summary>
        /// <param name="uId">用户编号</param>
        /// <returns>顶部导航</returns>
        public async Task<ApiReturn<authority_list>> GetAuthority_listShowinfor(string? uId)
        {
            ApiReturn<authority_list> apiReturn = new ApiReturn<authority_list>();
            var userRole = await employee_role_tableServices.GetShowQueryableAsync();
            var roleLimOne = await role_Permission_TableRepository.GetShowQueryableAsync();
            var lList = await authority_ListRepository.GetShowQueryableAsync();
            var list = (from a in userRole.ToList()
                        join b in roleLimOne.ToList()
                        on a.role_number equals b.role_number
                        join c in lList.ToList()
                        on b.authority_number equals c.authority_numbe
                        where (a.employee_number == uId)
                        select c).ToList();
            list = list.OrderBy(c => c.orderinfor).ToList();
            apiReturn.Code = 200;
            apiReturn.Message = "成功";
            apiReturn.ListInfor = list;
            return apiReturn;
        }



    }
}
